package com.imooc.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 产品类型枚举
 * Created By TINY
 * Create Time 2020/2/9 - 15:24
 **/
@Getter
@AllArgsConstructor
public enum ProductLine {

    PRODUCT1("阿猫", 1),
    PRODUCT2("阿狗", 2);

    /** 产品线描述 */
    private String description;

    /** 产品线代码 */
    private Integer code;

    public static ProductLine of(Integer code) {
        Objects.requireNonNull(code);

        return Stream.of(values()).filter(value -> value.code.equals(code))
                .findAny().orElseThrow(
                        () -> new IllegalArgumentException(
                                code + " 对应的产品线不存在"));
    }
}
